import { Metadata } from 'next'
import { getBiddingsForFailure } from '@/lib/bidding/service'
import { GetBiddingsSchema, searchParamsCache } from '@/lib/bidding/validation'
import { BiddingsFailureTable } from '@/lib/bidding/failure/biddings-failure-table'

export const metadata: Metadata = {
  title: '유찰입찰',
  description: '유찰된 입찰 내역을 확인하고 재입찰을 진행할 수 있습니다.',
}

interface BiddingFailurePageProps {
  searchParams: Promise<Record<string, string | string[] | undefined>>
}

export default async function BiddingFailurePage({
  searchParams,
}: BiddingFailurePageProps) {
  // URL 파라미터 검증
  const searchParamsResolved = await searchParams
  const search = searchParamsCache.parse(searchParamsResolved)

  // 데이터 조회
  const biddingsPromise = getBiddingsForFailure(search)

  return (
    <div className="flex flex-col gap-4 p-4">
      <div className="flex items-center justify-between">
        <div>
          <h1 className="text-2xl font-bold tracking-tight">유찰입찰</h1>
          <p className="text-muted-foreground">
            유찰된 입찰 내역을 확인하고 재입찰을 진행할 수 있습니다.
          </p>
        </div>
      </div>

      <BiddingsFailureTable promises={Promise.all([biddingsPromise])} />
    </div>
  )
}